package com.zlz.server.exception;

import com.zlz.server.pojo.RespBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

/**
 * @author: zlz
 * @date: 2021/1/22 22:48
 * @description: 全局异常处理
 * @since: JDK1.8
 */
@RestControllerAdvice
@Slf4j
public class GlobalException {
    @ExceptionHandler(SQLException.class)
    public RespBean mysqlExep(SQLException e) {
        log.error("数据库异常, 操作失败!", e);
        return RespBean.error("数据库异常, 操作失败!");
    }

    @ExceptionHandler(YebException.class)
    public RespBean yebExep(YebException e) {
        log.error("操作失败!", e);
        return RespBean.error(e.getMessage());
    }

    @ExceptionHandler(Throwable.class)
    public RespBean exep(Throwable e) {
        log.error("操作失败!", e);
        return RespBean.error(e.getMessage());
    }
}
